<template>
  <div class="timing">
    <el-row style="margin-bottom:10px;">
      <el-col :span="24">
        <el-button type="primary" @click="addUser('add')"><Icon type="md-add" />新增</el-button>
      </el-col>
    </el-row>
    <httb 
    @deleteSelectData="deleteSelectData"
     ref="httbRef" :table-col="tabUserList" 
     width="200"
     :table-data="tableUserData" @refresh="getUserList"
      @roleDist="roleDist" />
    <editdialog ref="editdialog" @refresh="getUserList" />
  </div>
</template>

<script>
import { getUserRoles, getPostList, userRoleAddEdit,delPost } from '@/api/home_'
import editdialog from './components/editDialog.vue'
export default {
  components: {
    editdialog
  },
  // primary  success info warning danger
  data() {
    return {
      formInline: {
        name: '',
        phone: ''
      },
      tableUserData: [],
      tabUserList: [
        {
          key: 'postName',
          title: '岗位名称 '
        },
        {
          key: 'postCode',
          title: '岗位编号'
        },
        {
          key: 'sort',
          title: '排序'
        },
        {
          key: 'status',
          title: '状态'
        },
        {
          key: 'remark',
          title: '备注信息'
        }
      ],
      visible: false,
      total: 0,
      size: 10,
      page: 1
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.getUserList()
    })
  },
  methods: {
    deleteSelectData(v) {
      delPost(v.id).then(res => {
        if (res.code == 200) {
          this.getUserList()
        } else {
          this.$notify.error({
            title: '错误',
            message: res.msg
          })
        }
      })
    },
    roleDist(v) {

    },
    // 用户角色列表
    getUserRolesList() {
      getUserRoles({}).then(res => {

      })
    },
    // 用户角色修改
    setUserRoleAddEdit() {
      userRoleAddEdit({
        roleIds: [],
        userId: ''
      }).then(res => {

      })
    },
    addUser(v) {
      this.$refs.editdialog.setVal(v)
    },
    editRowData(v) {
      this.$refs.editdialog.setVal(v)
    },
    handleSizeChange(v) {
      this.page = 1
      this.size = v
      this.getUserList()
    },
    handleCurrentChange(v) {
      this.page = v
      this.getUserList()
    },

    // 获取用户列表
    getUserList() {
      getPostList({
          page: this.page,
          size: this.size,
          name: this.formInline.name,
          phone: this.formInline.phone
      }).then(res => {
        this.tableUserData = res.data
        this.total = res.data.total
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .timing{
    background:#fff;
    padding:20px;
  }
</style>
